﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace DTC.Resources
{
    class TextBoxBindingValidationSetter
    {
        public void PrepareBinding(FrameworkElement Container)
        {
            BindingExpression expression;
            TextBox tmp;
            foreach (object child in LogicalTreeHelper.GetChildren(Container))
            {
                if (child is TextBox)
                {
                    tmp = child as TextBox;
                    expression = tmp.GetBindingExpression(TextBox.TextProperty);
                    if (expression != null)
                    {
                        expression.UpdateSource();
                    }
                }
                else
                {
                    if (child is FrameworkElement)
                        this.PrepareBinding(child as FrameworkElement);
                }
            }
        }
    }
}
